import { FlowApplyInput } from '@/model/flowApply';
import Http from '../http';
import dayjs from 'dayjs';

//获取所有申请流程数据
export const GetAllFlowApplyList = async function (pageResultModel: FlowApplyInput) {
  pageResultModel.CreateTimeStart = undefined;
  pageResultModel.CreateTimeEnd = undefined;
  if (pageResultModel.CreateTime && pageResultModel.CreateTime.length === 2) {
    pageResultModel.CreateTimeStart = dayjs(pageResultModel.CreateTime[0]).format('YYYY-MM-DD');
    pageResultModel.CreateTimeEnd = dayjs(pageResultModel.CreateTime[1]).format('YYYY-MM-DD');
  }

  return await Http.post('/api/FlowApply/GetAllFlowApplyList', pageResultModel);
}

//新增流程申请
export const InsertFlowApply = function (flowApply: any) {
  return Http.post('/api/FlowApply/Insert', flowApply)
}

//根据申请id获取数据
export const GetFlowApplyByApplyId = async function (params: { flowApplyId: string }) {
  return await Http.get('/api/FlowApply/GetFlowApplyByApplyId', params);
}

//获取已审核节点数据
export const GetExamineNodeData = async function (params: { flowApplyId: string }) {
  return await Http.get('/api/FlowApply/GetExamineNodeData', params);
}

//获取等待审批流程
export const GetWaitApprovalFlow = async function (pageResultModel: FlowApplyInput) {
  pageResultModel.CreateTimeStart = undefined;
  pageResultModel.CreateTimeEnd = undefined;
  if (pageResultModel.CreateTime && pageResultModel.CreateTime.length === 2) {
    pageResultModel.CreateTimeStart = dayjs(pageResultModel.CreateTime[0]).format('YYYY-MM-DD');
    pageResultModel.CreateTimeEnd = dayjs(pageResultModel.CreateTime[1]).format('YYYY-MM-DD');
  }
  return await Http.post('/api/FlowApply/GetWaitApprovalFlow', pageResultModel);
}

//获取已审核审批流程
export const GetAuditedApprovalFlow = async function (pageResultModel: FlowApplyInput) {
  pageResultModel.CreateTimeStart = undefined;
  pageResultModel.CreateTimeEnd = undefined;
  if (pageResultModel.CreateTime && pageResultModel.CreateTime.length === 2) {
    pageResultModel.CreateTimeStart = dayjs(pageResultModel.CreateTime[0]).format('YYYY-MM-DD');
    pageResultModel.CreateTimeEnd = dayjs(pageResultModel.CreateTime[1]).format('YYYY-MM-DD');
  }
  return await Http.post('/api/FlowApply/GetAuditedApprovalFlow', pageResultModel);
}

//获取抄送流程
export const GetCarbonCopyFlow = async function (pageResultModel: FlowApplyInput) {
  pageResultModel.CreateTimeStart = undefined;
  pageResultModel.CreateTimeEnd = undefined;
  if (pageResultModel.CreateTime && pageResultModel.CreateTime.length === 2) {
    pageResultModel.CreateTimeStart = dayjs(pageResultModel.CreateTime[0]).format('YYYY-MM-DD');
    pageResultModel.CreateTimeEnd = dayjs(pageResultModel.CreateTime[1]).format('YYYY-MM-DD');
  }
  return await Http.post('/api/FlowApply/GetCarbonCopyFlow', pageResultModel);
}

//流程申请审核
export const FlowApplyExamine = function (flowApplyExamineInput: any) {
  return Http.post('/api/FlowApply/FlowApplyExamine', flowApplyExamineInput)
}

//获取申请当前节点前的所有节点数据（下拉框）
export const GetExamineNodeSelectData = async function (params: { flowApplyId: string }) {
  return await Http.get('/api/FlowApply/GetExamineNodeSelectData', params);
}


//更新流程状态
export const UpdateFlowApplyState = async function (params: { flowApplyId: string, flowApplyState: number }) {
  return await Http.get('/api/FlowApply/UpdateFlowApplyState', params);
}

//获取当前登录人流程消息
export const GetFlowMessage = async function () {
  return await Http.get('/api/FlowApply/GetFlowMessage');
}

//新增消息
export const InsertMessage =async function (params: { flowApplyId: string, recipientKeys: string,messageType:number }) {
  return await Http.get('/api/FlowApply/InsertMessage',params);
}




